/**
 * 静态菜单配置
 * 基于前端路由结构构建的菜单数据
 * 避免从后端API获取菜单数据时的字符编码问题
 */

export const staticMenuConfig = [
  {
    id: 1,
    menuName: '首页',
    menuUrl: '/dashboard',
    menuIcon: 'dashboard',
    orderNum: 1,
    hidden: false,
    status: 1,
    children: []
  },
  {
    id: 2,
    menuName: '碳资产管理',
    menuUrl: '/assets',
    menuIcon: 'tree',
    orderNum: 2,
    hidden: false,
    status: 1,
    children: [
      {
        id: 21,
        menuName: '碳配额',
        menuUrl: '/carbonAssets/quota',
        menuIcon: 'table',
        orderNum: 1,
        hidden: false,
        status: 1,
        children: []
      },
          {
            id: 22,
            menuName: '碳信用',
            menuUrl: '/carbonAssets/credit',
            menuIcon: 'star',
            orderNum: 2,
            hidden: false,
            status: 1,
            children: []
          },
      {
        id: 27,
        menuName: '开发立项',
        menuUrl: '/carbonAssets/dev/projectDevHome',
        menuIcon: 'form',
        orderNum: 3,
        hidden: false,
        status: 1,
        children: []
      },
      {
        id: 28,
        menuName: '开发进度',
        menuUrl: '/carbonAssets/dev/projectSchedule',
        menuIcon: 'chart',
        orderNum: 4,
        hidden: false,
        status: 1,
        children: []
      },
      {
        id: 29,
        menuName: '项目文档管理',
        menuUrl: '/carbonAssets/dev/projectFile',
        menuIcon: 'document',
        orderNum: 5,
        hidden: false,
        status: 1,
        children: []
      }
    ]
  },
  {
    id: 3,
    menuName: '碳交易管理',
    menuUrl: '/trade',
    menuIcon: 'money',
    orderNum: 3,
    hidden: false,
    status: 1,
    children: [
      {
        id: 31,
        menuName: '交易所管理',
        menuUrl: '/trade/account/exchange/',
        menuIcon: 'shopping',
        orderNum: 1,
        hidden: false,
        status: 1,
        children: []
      },
      {
        id: 32,
        menuName: '交易账号管理',
        menuUrl: '/trade/account/manager/',
        menuIcon: 'user',
        orderNum: 2,
        hidden: false,
        status: 1,
        children: []
      }
    ]
  },
  {
    id: 10,
    menuName: '碳交易行情',
    menuUrl: '/carbonQuote',
    menuIcon: 'chart',
    orderNum: 10,
    hidden: false,
    status: 1,
    children: [
      {
        id: 101,
        menuName: '供需行情',
        menuUrl: '/carbonQuote/quotation',
        menuIcon: 'table',
        orderNum: 1,
        hidden: false,
        status: 1,
        children: []
      },
      {
        id: 102,
        menuName: '询报价管理',
        menuUrl: '/carbonQuote/offer',
        menuIcon: 'edit',
        orderNum: 2,
        hidden: false,
        status: 1,
        children: []
      }
    ]
  },
  {
    id: 6,
    menuName: '系统管理',
    menuUrl: '/sys',
    menuIcon: 'setting',
    orderNum: 4,
    hidden: false,
    status: 1,
    children: [
      {
        id: 61,
        menuName: '系统咨询管理',
        menuUrl: '/sys/information',
        menuIcon: 'message',
        orderNum: 1,
        hidden: false,
        status: 1,
        children: []
      },
      {
        id: 63,
        menuName: '项目库管理',
        menuUrl: '/sys/metaregistry',
        menuIcon: 'component',
        orderNum: 3,
        hidden: false,
        status: 1,
        children: []
      },
      {
        id: 64,
        menuName: '方法学管理',
        menuUrl: '/sys/methodology',
        menuIcon: 'education',
        orderNum: 4,
        hidden: false,
        status: 1,
        children: []
      },
      {
        id: 65,
        menuName: '基础管理',
        menuUrl: '/sys/base',
        menuIcon: 'clipboard',
        orderNum: 5,
        hidden: false,
        status: 1,
        children: [
          {
            id: 651,
            menuName: '角色管理',
            menuUrl: '/sys/base/sysRole',
            menuIcon: 'peoples',
            orderNum: 1,
            hidden: false,
            status: 1,
            children: []
          },
          {
            id: 652,
            menuName: '字典管理',
            menuUrl: '/sys/base/sysDict',
            menuIcon: 'list',
            orderNum: 2,
            hidden: false,
            status: 1,
            children: []
          },
          {
            id: 654,
            menuName: '账户管理',
            menuUrl: '/sys/base/sysTenant',
            menuIcon: 'user',
            orderNum: 3,
            hidden: false,
            status: 1,
            children: []
          }
        ]
      },
      {
        id: 66,
        menuName: '平台服务管理',
        menuUrl: '/sys/business',
        menuIcon: 'shopping',
        orderNum: 6,
        hidden: false,
        status: 1,
        children: []
      },
      {
        id: 67,
        menuName: '平台审批管理',
        menuUrl: '/sys/approve',
        menuIcon: 'star',
        orderNum: 7,
        hidden: false,
        status: 1,
        children: []
      },
      {
        id: 68,
        menuName: '租户管理',
        menuUrl: '/sys/tenantMgt',
        menuIcon: 'peoples',
        orderNum: 8,
        hidden: false,
        status: 1,
        children: []
      },
      {
        id: 69,
        menuName: '系统项目文档管理',
        menuUrl: '/sys/projectFile',
        menuIcon: 'documentation',
        orderNum: 9,
        hidden: false,
        status: 1,
        children: []
      }
    ]
  },
  {
    id: 9,
    menuName: '企业信息',
    menuUrl: '/account/companyInfo',
    menuIcon: 'peoples',
    orderNum: 5,
    hidden: false,
    status: 1,
    children: []
  },
  {
    id: 11,
    menuName: '碳资讯',
    menuUrl: '/carbonNewsManager/',
    menuIcon: 'documentation',
    orderNum: 6,
    hidden: false,
    status: 1,
    children: []
  }
];

/**
 * 获取静态菜单数据
 * @returns {Array} 菜单数据数组
 */
export function getStaticMenus() {
  return staticMenuConfig;
}

/**
 * 根据ID查找菜单项
 * @param {number} id 菜单ID
 * @param {Array} menus 菜单数组，默认为根菜单
 * @returns {Object|null} 找到的菜单项或null
 */
export function findMenuById(id, menus = staticMenuConfig) {
  for (const menu of menus) {
    if (menu.id === id) {
      return menu;
    }
    if (menu.children && menu.children.length > 0) {
      const found = findMenuById(id, menu.children);
      if (found) {
        return found;
      }
    }
  }
  return null;
}

/**
 * 根据URL查找菜单项
 * @param {string} url 菜单URL
 * @param {Array} menus 菜单数组，默认为根菜单
 * @returns {Object|null} 找到的菜单项或null
 */
export function findMenuByUrl(url, menus = staticMenuConfig) {
  for (const menu of menus) {
    if (menu.menuUrl === url) {
      return menu;
    }
    if (menu.children && menu.children.length > 0) {
      const found = findMenuByUrl(url, menu.children);
      if (found) {
        return found;
      }
    }
  }
  return null;
}
